<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="./css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" type="text/css" href="css/userInquiry.css" />
	</head>

	<body onload="body_onload()">
		<div class="mui-content">
			<!-- 查询用户信息 -->
			<form class="mui-input-group">
				<div class="mui-input-row mui-plus-visible usermessege">
					<label>用户号：</label>
					<input id="userId" type="number" class="mui-input-speech mui-input-clear" placeholder="手动输入或语音输入">
				</div>
				<div class="a_Image">
					<a id="confirm" href="javascript:;"><img src="./images/arrow1.png" ></a>
				</div>
				<div class="mui-button-row">
					<button id="quiryInfo" type="button" class="mui-btn mui-btn-primary mui-btn-block" onclick="return false;">查询</button>&nbsp;&nbsp;
				</div>
			</form>
			<div class="sorage_input">
				<input type="text" name="" id="sorage_value" value="" />
			</div>
			<div class="mainInfo">
				<!-- <div class="imgInfo"> -->
				<img id="userImage" src="images/userImage.jpg">
				<!-- </div> -->
			</div>
			<div class="mainUserInfo">
				<div class="userInfo">
					<ul id="userInfoClass" class="mui-table-view mui-table-view-chevron">
						<li class="mui-table-view-cell">
							<a id="userName" href="javascript:;" class="mui-navigate-right">户主：</a>
						</li>
						<li class="mui-table-view-cell">
							<a id="userPhone" href="javascript:;" class="mui-navigate-right">电话：</a>
						</li>
						<li class="mui-table-view-cell">
							<a id="userAddress" href="javascript:;" class="mui-navigate-right">地址：</a>
						</li>
						<li class="mui-table-view-cell">
							<a id="idNumber" href="javascript:;" class="mui-navigate-right">身份证号：</a>
						</li>
					</ul>
					<!-- <input type="text" name="" id="username" value="" /> --><!-- <span id="username">户主：</span> -->
				</div>
			</div>
			<div class="secondaryInfo">
				<div class="items">
					<span>用户编号：</span><span class="dataInfo" id="userid"></span>
				</div>
				<div class="items">
					<span>使用状态：</span><span class="dataInfo" id="status"></span>
				</div>
				<div class="items">
					<span>所在册号：</span><span class="dataInfo" id="recordId"></span>
				</div>
				<div class="items">
					<span>是否阶梯：</span><span class="dataInfo" id="step"></span>
				</div>
				<div class="items">
					<span>当前结余：</span><span class="dataInfo" id="surPlus"></span>
				</div>
				<div class="items">
					<span>用水人口：</span><span class="dataInfo" id="population"></span>
				</div>
				<div class="items">
					<span>快速抄表号：</span><span class="dataInfo" id="waterReadIDs"></span>
				</div>
				<div class="items">
					<span>水表出厂号：</span><span class="dataInfo" id="WaterFactorID"></span>
				</div>
			</div>
		</div>

		<script src="./js/mui.min.js"></script>
		<script src="js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<!-- <script src="http://103.59.149.116:6198/hcys/js/mapi.js" type="text/javascript" charset="utf-8"></script> -->
		<script src="js/Mobile.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
		<!-- <script src="./js/Token.js" type="text/javascript" charset="utf-8"></script> -->
		<script type="text/javascript">
			mui.init({
				keyEventBind: {
					backbutton: false //关闭back按键监听
				}
			});

			function body_onload() {
				mui.plusReady(function() {
					plus.key.addEventListener("backbutton", function() {
						// alert("33")
						mui.toast('再按一次退出应用',{ duration:'long', type:'div' });
						setTimeout(function(){
							plus.key.removeEventListener("backbutton",function(){});
						},3000);
						plus.key.addEventListener("backbutton", function() {
							// mui.toast('再按二次退出应用',{ duration:'long', type:'div' });
							plus.runtime.quit();
							plus.webview.close(plus.webview.all());
						}, false);
					}, false);
				})
			}
			// mui.init();
			mui.plusReady(function() {
				// by name query
				mui(".a_Image").on("tap", "#confirm", function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;
					if (checkToken(glbToken).status == "ok") {
						mui.openWindow({
							url: "byNameQuery.html",
							id: "byNameQuery.html"
						})
					} else{
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function(){
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						},30);
					}
				});
				
				// 监听byNameQuery返回的结果
				window.addEventListener("select",function(e){
					$("#userId").val(e.detail.userIdList);
				})
				
				// 查询
				$("#quiryInfo").click(function() {
					var myStorage = JSON.parse(localStorage.getItem("users"));
					var glbToken = myStorage.glbToken;
					if (checkToken(glbToken).status == "ok") {
						var userId = $("#userId").val();
						$("#sorage_value").val(userId);
						if (userId == "" || userId == null) {
							alert("请输入用户号");
						} else if (typeof getUserInfo(userId, glbToken).status != "undefined") {
							var userInfoManage = getUserInfo(userId, glbToken);
							$("#userName").text("户主：" + userInfoManage.UserName);
							$("#userPhone").text("电话：" + userInfoManage.Phone);
							$("#userAddress").text("地址：" + userInfoManage.UserAddress);
							$("#idNumber").text("身份证号：" + userInfoManage.IDNumber);
							var url = "http://103.59.149.116:6198/lnhy";
							var imgUrl = userInfoManage.Image;
							if (imgUrl != "") {
								// if (imgUrl.substr(0, 2) == "..") {
								imgUrl = (imgUrl || '').substr(2);
								// }
								$("#userImage").attr("src", url + imgUrl);
							}
							// secondInfo显示
							var userid = document.getElementById("userid");
							userid.innerText = userInfoManage.UserID;
							// var idNumber = document.getElementById("idNumber");
							// idNumber.innerText = userInfoManage.IDNumber;
							var status = document.getElementById("status");
							status.innerText = userInfoManage.Status;
							var recordId = document.getElementById("recordId");
							recordId.innerText = userInfoManage.RecordID;
							var step = document.getElementById("step");
							step.innerText = userInfoManage.Step;
							var surPlus = document.getElementById("surPlus");
							surPlus.innerText = userInfoManage.Surplus;
							var population = document.getElementById("population");
							population.innerText = userInfoManage.Population;
							var waterReadIDs = document.getElementById("waterReadIDs");
							waterReadIDs.innerText = userInfoManage.WaterReadIDs;
							var WaterFactorID = document.getElementById('WaterFactorID');
							WaterFactorID.innerText = userInfoManage.WaterFactorID;
						} else {
							alert("请检查用户号是否正确")
						}
					} else {
						app.setState({});
						plus.webview.getLaunchWebview().show("pop-in");
						setTimeout(function() {
							alert("此账号已在其他设备登录,请重新登录!");
							localStorage.clear();
							plus.runtime.restart();
						}, 30);
					}
				});
				
				// 更新用户信息
				mui("#userInfoClass").on("tap", "#userName", function(){
					var userId = $("#sorage_value").val();
					mui.openWindow({
						url: "updateUserName.html",
						id: "updateUserName.html",
						extras:{
							userId:userId
						}
					})
				})
				mui("#userInfoClass").on("tap", "#userPhone", function(){
					var userId = $("#sorage_value").val();
					mui.openWindow({
						url: "updateUserPhone.html",
						id: "updateUserPhone.html",
						extras:{
							userId:userId
						}
					})
				})
				mui("#userInfoClass").on("tap", "#userAddress", function(){
					var userId = $("#sorage_value").val();
					mui.openWindow({
						url: "updateUserAddress.html",
						id: "updateUserAddress.html",
						extras:{
							userId:userId
						}
					})
				})
				mui("#userInfoClass").on("tap", "#idNumber", function(){
					var userId = $("#sorage_value").val();
					mui.openWindow({
						url: "updateUserIdNum.html",
						id: "updateUserIdNum.html",
						extras:{
							userId:userId
						}
					})
				})
			});
		</script>
	</body>

</html>
